// $ANTLR 3.2 Sep 23, 2009 12:02:23 D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g 2010-07-13 11:28:55

	package parser;
	import java.util.Set;
	import java.util.HashSet;


import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;

import org.antlr.runtime.tree.*;

public class TBTParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "SPATIU", "INDENT", "DEDENT", "FORALL", "ARROW", "TLAMBDA", "LAMBDA", "DOT", "SEMI", "EQ", "BIND", "OR", "DARROW", "STAR", "LETREC", "LET", "CASE", "OF", "IND", "COIND", "LPAREN", "RPAREN", "LCURLY", "RCURLY", "LANG", "RANG", "COLUMN", "ID", "TID", "WS", "COMMENT", "PROG", "PROLOG", "TERM", "TL_BINDING", "TL_BINDINGS", "LAM_ABS", "LAM_APP", "VAR", "TYPE_ABS", "TYPE_APP", "TVAR", "BRANCHES", "BRANCH", "FUNCTION", "FOR_ALL", "TCONS_APP", "DATATYPE", "TARGS", "TCONSTRUCTORS", "TCONS", "STARED_TYPE"
    };
    public static final int FUNCTION=48;
    public static final int TERM=37;
    public static final int STAR=17;
    public static final int STARED_TYPE=55;
    public static final int TCONS_APP=50;
    public static final int CASE=20;
    public static final int DEDENT=6;
    public static final int BRANCHES=46;
    public static final int ID=31;
    public static final int EOF=-1;
    public static final int INDENT=5;
    public static final int LPAREN=24;
    public static final int LAM_APP=41;
    public static final int RPAREN=25;
    public static final int LETREC=18;
    public static final int IND=22;
    public static final int PROG=35;
    public static final int RANG=29;
    public static final int BIND=14;
    public static final int LAM_ABS=40;
    public static final int COLUMN=30;
    public static final int TVAR=45;
    public static final int DARROW=16;
    public static final int TID=32;
    public static final int VAR=42;
    public static final int LAMBDA=10;
    public static final int EQ=13;
    public static final int TL_BINDING=38;
    public static final int COMMENT=34;
    public static final int DOT=11;
    public static final int SPATIU=4;
    public static final int TARGS=52;
    public static final int TCONSTRUCTORS=53;
    public static final int TYPE_ABS=43;
    public static final int FORALL=7;
    public static final int TL_BINDINGS=39;
    public static final int FOR_ALL=49;
    public static final int LCURLY=26;
    public static final int TYPE_APP=44;
    public static final int OF=21;
    public static final int SEMI=12;
    public static final int TLAMBDA=9;
    public static final int WS=33;
    public static final int RCURLY=27;
    public static final int OR=15;
    public static final int BRANCH=47;
    public static final int PROLOG=36;
    public static final int ARROW=8;
    public static final int DATATYPE=51;
    public static final int TCONS=54;
    public static final int COIND=23;
    public static final int LET=19;
    public static final int LANG=28;

    // delegates
    // delegators


        public TBTParser(TokenStream input) {
            this(input, new RecognizerSharedState());
        }
        public TBTParser(TokenStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        
    protected TreeAdaptor adaptor = new CommonTreeAdaptor();

    public void setTreeAdaptor(TreeAdaptor adaptor) {
        this.adaptor = adaptor;
    }
    public TreeAdaptor getTreeAdaptor() {
        return adaptor;
    }

    public String[] getTokenNames() { return TBTParser.tokenNames; }
    public String getGrammarFileName() { return "D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g"; }


      // Arrow is right associative
      private Tree createArrowTree(Tree first , List rest, List arrows){
        Tree crt , root1;
          
        rest.add(0,first);
        crt = (Tree)rest.get(rest.size()-1);
        
        for( int i = rest.size()-2; i >= 0; i--){
          Tree tmpRoot = (Tree)adaptor.nil();
          adaptor.addChild( tmpRoot, rest.get(i));
          adaptor.addChild( tmpRoot, crt);
          crt = (Tree) adaptor.becomeRoot( (Token) arrows.get(i), tmpRoot);
        }

        return crt;
      }
      private Set<String> ctors = new HashSet<String>();
      


    public static class program_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "program"
    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:68:1: program : prolog ( tl_binding )* term -> ^( PROG prolog ^( TL_BINDINGS ( tl_binding )* ) ^( TERM term ) ) ;
    public final TBTParser.program_return program() throws RecognitionException {
        TBTParser.program_return retval = new TBTParser.program_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        TBTParser.prolog_return prolog1 = null;

        TBTParser.tl_binding_return tl_binding2 = null;

        TBTParser.term_return term3 = null;


        RewriteRuleSubtreeStream stream_prolog=new RewriteRuleSubtreeStream(adaptor,"rule prolog");
        RewriteRuleSubtreeStream stream_term=new RewriteRuleSubtreeStream(adaptor,"rule term");
        RewriteRuleSubtreeStream stream_tl_binding=new RewriteRuleSubtreeStream(adaptor,"rule tl_binding");
        try {
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:69:5: ( prolog ( tl_binding )* term -> ^( PROG prolog ^( TL_BINDINGS ( tl_binding )* ) ^( TERM term ) ) )
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:69:7: prolog ( tl_binding )* term
            {
            pushFollow(FOLLOW_prolog_in_program184);
            prolog1=prolog();

            state._fsp--;
            if (state.failed) return retval;
            if ( state.backtracking==0 ) stream_prolog.add(prolog1.getTree());
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:69:14: ( tl_binding )*
            loop1:
            do {
                int alt1=2;
                int LA1_0 = input.LA(1);

                if ( (LA1_0==LET) ) {
                    alt1=1;
                }


                switch (alt1) {
            	case 1 :
            	    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:69:14: tl_binding
            	    {
            	    pushFollow(FOLLOW_tl_binding_in_program186);
            	    tl_binding2=tl_binding();

            	    state._fsp--;
            	    if (state.failed) return retval;
            	    if ( state.backtracking==0 ) stream_tl_binding.add(tl_binding2.getTree());

            	    }
            	    break;

            	default :
            	    break loop1;
                }
            } while (true);

            pushFollow(FOLLOW_term_in_program189);
            term3=term();

            state._fsp--;
            if (state.failed) return retval;
            if ( state.backtracking==0 ) stream_term.add(term3.getTree());


            // AST REWRITE
            // elements: term, prolog, tl_binding
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            if ( state.backtracking==0 ) {
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 69:31: -> ^( PROG prolog ^( TL_BINDINGS ( tl_binding )* ) ^( TERM term ) )
            {
                // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:69:34: ^( PROG prolog ^( TL_BINDINGS ( tl_binding )* ) ^( TERM term ) )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(PROG, "PROG"), root_1);

                adaptor.addChild(root_1, stream_prolog.nextTree());
                // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:69:48: ^( TL_BINDINGS ( tl_binding )* )
                {
                Object root_2 = (Object)adaptor.nil();
                root_2 = (Object)adaptor.becomeRoot((Object)adaptor.create(TL_BINDINGS, "TL_BINDINGS"), root_2);

                // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:69:62: ( tl_binding )*
                while ( stream_tl_binding.hasNext() ) {
                    adaptor.addChild(root_2, stream_tl_binding.nextTree());

                }
                stream_tl_binding.reset();

                adaptor.addChild(root_1, root_2);
                }
                // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:69:75: ^( TERM term )
                {
                Object root_2 = (Object)adaptor.nil();
                root_2 = (Object)adaptor.becomeRoot((Object)adaptor.create(TERM, "TERM"), root_2);

                adaptor.addChild(root_2, stream_term.nextTree());

                adaptor.addChild(root_1, root_2);
                }

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;}
            }

            retval.stop = input.LT(-1);

            if ( state.backtracking==0 ) {

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "program"

    public static class prolog_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "prolog"
    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:71:1: prolog : ( datatype )* -> ^( PROLOG ( datatype )* ) ;
    public final TBTParser.prolog_return prolog() throws RecognitionException {
        TBTParser.prolog_return retval = new TBTParser.prolog_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        TBTParser.datatype_return datatype4 = null;


        RewriteRuleSubtreeStream stream_datatype=new RewriteRuleSubtreeStream(adaptor,"rule datatype");
        try {
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:72:5: ( ( datatype )* -> ^( PROLOG ( datatype )* ) )
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:72:7: ( datatype )*
            {
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:72:7: ( datatype )*
            loop2:
            do {
                int alt2=2;
                int LA2_0 = input.LA(1);

                if ( (LA2_0==IND) ) {
                    alt2=1;
                }


                switch (alt2) {
            	case 1 :
            	    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:72:7: datatype
            	    {
            	    pushFollow(FOLLOW_datatype_in_prolog224);
            	    datatype4=datatype();

            	    state._fsp--;
            	    if (state.failed) return retval;
            	    if ( state.backtracking==0 ) stream_datatype.add(datatype4.getTree());

            	    }
            	    break;

            	default :
            	    break loop2;
                }
            } while (true);



            // AST REWRITE
            // elements: datatype
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            if ( state.backtracking==0 ) {
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 72:17: -> ^( PROLOG ( datatype )* )
            {
                // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:72:20: ^( PROLOG ( datatype )* )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(PROLOG, "PROLOG"), root_1);

                // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:72:29: ( datatype )*
                while ( stream_datatype.hasNext() ) {
                    adaptor.addChild(root_1, stream_datatype.nextTree());

                }
                stream_datatype.reset();

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;}
            }

            retval.stop = input.LT(-1);

            if ( state.backtracking==0 ) {

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "prolog"

    public static class tl_binding_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "tl_binding"
    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:75:1: tl_binding : LET LANG type RANG ID BIND term COLUMN -> ^( TL_BINDING ID type term ) ;
    public final TBTParser.tl_binding_return tl_binding() throws RecognitionException {
        TBTParser.tl_binding_return retval = new TBTParser.tl_binding_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token LET5=null;
        Token LANG6=null;
        Token RANG8=null;
        Token ID9=null;
        Token BIND10=null;
        Token COLUMN12=null;
        TBTParser.type_return type7 = null;

        TBTParser.term_return term11 = null;


        Object LET5_tree=null;
        Object LANG6_tree=null;
        Object RANG8_tree=null;
        Object ID9_tree=null;
        Object BIND10_tree=null;
        Object COLUMN12_tree=null;
        RewriteRuleTokenStream stream_RANG=new RewriteRuleTokenStream(adaptor,"token RANG");
        RewriteRuleTokenStream stream_ID=new RewriteRuleTokenStream(adaptor,"token ID");
        RewriteRuleTokenStream stream_BIND=new RewriteRuleTokenStream(adaptor,"token BIND");
        RewriteRuleTokenStream stream_LET=new RewriteRuleTokenStream(adaptor,"token LET");
        RewriteRuleTokenStream stream_LANG=new RewriteRuleTokenStream(adaptor,"token LANG");
        RewriteRuleTokenStream stream_COLUMN=new RewriteRuleTokenStream(adaptor,"token COLUMN");
        RewriteRuleSubtreeStream stream_term=new RewriteRuleSubtreeStream(adaptor,"rule term");
        RewriteRuleSubtreeStream stream_type=new RewriteRuleSubtreeStream(adaptor,"rule type");
        try {
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:76:5: ( LET LANG type RANG ID BIND term COLUMN -> ^( TL_BINDING ID type term ) )
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:76:7: LET LANG type RANG ID BIND term COLUMN
            {
            LET5=(Token)match(input,LET,FOLLOW_LET_in_tl_binding248); if (state.failed) return retval; 
            if ( state.backtracking==0 ) stream_LET.add(LET5);

            LANG6=(Token)match(input,LANG,FOLLOW_LANG_in_tl_binding250); if (state.failed) return retval; 
            if ( state.backtracking==0 ) stream_LANG.add(LANG6);

            pushFollow(FOLLOW_type_in_tl_binding252);
            type7=type();

            state._fsp--;
            if (state.failed) return retval;
            if ( state.backtracking==0 ) stream_type.add(type7.getTree());
            RANG8=(Token)match(input,RANG,FOLLOW_RANG_in_tl_binding254); if (state.failed) return retval; 
            if ( state.backtracking==0 ) stream_RANG.add(RANG8);

            ID9=(Token)match(input,ID,FOLLOW_ID_in_tl_binding256); if (state.failed) return retval; 
            if ( state.backtracking==0 ) stream_ID.add(ID9);

            BIND10=(Token)match(input,BIND,FOLLOW_BIND_in_tl_binding258); if (state.failed) return retval; 
            if ( state.backtracking==0 ) stream_BIND.add(BIND10);

            pushFollow(FOLLOW_term_in_tl_binding260);
            term11=term();

            state._fsp--;
            if (state.failed) return retval;
            if ( state.backtracking==0 ) stream_term.add(term11.getTree());
            COLUMN12=(Token)match(input,COLUMN,FOLLOW_COLUMN_in_tl_binding262); if (state.failed) return retval; 
            if ( state.backtracking==0 ) stream_COLUMN.add(COLUMN12);



            // AST REWRITE
            // elements: type, ID, term
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            if ( state.backtracking==0 ) {
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 76:46: -> ^( TL_BINDING ID type term )
            {
                // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:76:49: ^( TL_BINDING ID type term )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(TL_BINDING, "TL_BINDING"), root_1);

                adaptor.addChild(root_1, stream_ID.nextNode());
                adaptor.addChild(root_1, stream_type.nextTree());
                adaptor.addChild(root_1, stream_term.nextTree());

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;}
            }

            retval.stop = input.LT(-1);

            if ( state.backtracking==0 ) {

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "tl_binding"

    public static class arrow_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "arrow"
    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:80:1: arrow : ARROW ;
    public final TBTParser.arrow_return arrow() throws RecognitionException {
        TBTParser.arrow_return retval = new TBTParser.arrow_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token ARROW13=null;

        Object ARROW13_tree=null;

        try {
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:80:7: ( ARROW )
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:80:9: ARROW
            {
            root_0 = (Object)adaptor.nil();

            ARROW13=(Token)match(input,ARROW,FOLLOW_ARROW_in_arrow293); if (state.failed) return retval;
            if ( state.backtracking==0 ) {
            ARROW13_tree = (Object)adaptor.create(ARROW13);
            adaptor.addChild(root_0, ARROW13_tree);
            }

            }

            retval.stop = input.LT(-1);

            if ( state.backtracking==0 ) {

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "arrow"

    public static class star_type_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "star_type"
    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:81:1: star_type : type ;
    public final TBTParser.star_type_return star_type() throws RecognitionException {
        TBTParser.star_type_return retval = new TBTParser.star_type_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        TBTParser.type_return type14 = null;



        try {
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:81:11: ( type )
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:81:13: type
            {
            root_0 = (Object)adaptor.nil();

            pushFollow(FOLLOW_type_in_star_type300);
            type14=type();

            state._fsp--;
            if (state.failed) return retval;
            if ( state.backtracking==0 ) adaptor.addChild(root_0, type14.getTree());

            }

            retval.stop = input.LT(-1);

            if ( state.backtracking==0 ) {

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "star_type"

    public static class type_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "type"
    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:82:1: type : ( FORALL TID DOT type -> ^( FOR_ALL TID type ) | first= type_app ( ( ARROW )=> arrow ta= type_app )* ->);
    public final TBTParser.type_return type() throws RecognitionException {
        TBTParser.type_return retval = new TBTParser.type_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token FORALL15=null;
        Token TID16=null;
        Token DOT17=null;
        TBTParser.type_app_return first = null;

        TBTParser.type_app_return ta = null;

        TBTParser.type_return type18 = null;

        TBTParser.arrow_return arrow19 = null;


        Object FORALL15_tree=null;
        Object TID16_tree=null;
        Object DOT17_tree=null;
        RewriteRuleTokenStream stream_FORALL=new RewriteRuleTokenStream(adaptor,"token FORALL");
        RewriteRuleTokenStream stream_TID=new RewriteRuleTokenStream(adaptor,"token TID");
        RewriteRuleTokenStream stream_DOT=new RewriteRuleTokenStream(adaptor,"token DOT");
        RewriteRuleSubtreeStream stream_arrow=new RewriteRuleSubtreeStream(adaptor,"rule arrow");
        RewriteRuleSubtreeStream stream_type_app=new RewriteRuleSubtreeStream(adaptor,"rule type_app");
        RewriteRuleSubtreeStream stream_type=new RewriteRuleSubtreeStream(adaptor,"rule type");

          List rest = new ArrayList();
          List arrows = new ArrayList();

        try {
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:87:5: ( FORALL TID DOT type -> ^( FOR_ALL TID type ) | first= type_app ( ( ARROW )=> arrow ta= type_app )* ->)
            int alt4=2;
            int LA4_0 = input.LA(1);

            if ( (LA4_0==FORALL) ) {
                alt4=1;
            }
            else if ( (LA4_0==LPAREN||LA4_0==TID) ) {
                alt4=2;
            }
            else {
                if (state.backtracking>0) {state.failed=true; return retval;}
                NoViableAltException nvae =
                    new NoViableAltException("", 4, 0, input);

                throw nvae;
            }
            switch (alt4) {
                case 1 :
                    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:87:7: FORALL TID DOT type
                    {
                    FORALL15=(Token)match(input,FORALL,FOLLOW_FORALL_in_type317); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_FORALL.add(FORALL15);

                    TID16=(Token)match(input,TID,FOLLOW_TID_in_type319); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_TID.add(TID16);

                    DOT17=(Token)match(input,DOT,FOLLOW_DOT_in_type321); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_DOT.add(DOT17);

                    pushFollow(FOLLOW_type_in_type323);
                    type18=type();

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) stream_type.add(type18.getTree());


                    // AST REWRITE
                    // elements: type, TID
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    if ( state.backtracking==0 ) {
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 88:9: -> ^( FOR_ALL TID type )
                    {
                        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:88:12: ^( FOR_ALL TID type )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(FOR_ALL, "FOR_ALL"), root_1);

                        adaptor.addChild(root_1, stream_TID.nextNode());
                        adaptor.addChild(root_1, stream_type.nextTree());

                        adaptor.addChild(root_0, root_1);
                        }

                    }

                    retval.tree = root_0;}
                    }
                    break;
                case 2 :
                    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:89:7: first= type_app ( ( ARROW )=> arrow ta= type_app )*
                    {
                    pushFollow(FOLLOW_type_app_in_type351);
                    first=type_app();

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) stream_type_app.add(first.getTree());
                    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:89:22: ( ( ARROW )=> arrow ta= type_app )*
                    loop3:
                    do {
                        int alt3=2;
                        int LA3_0 = input.LA(1);

                        if ( (LA3_0==ARROW) && (synpred1_TBTParser())) {
                            alt3=1;
                        }


                        switch (alt3) {
                    	case 1 :
                    	    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:89:23: ( ARROW )=> arrow ta= type_app
                    	    {
                    	    pushFollow(FOLLOW_arrow_in_type358);
                    	    arrow19=arrow();

                    	    state._fsp--;
                    	    if (state.failed) return retval;
                    	    if ( state.backtracking==0 ) stream_arrow.add(arrow19.getTree());
                    	    pushFollow(FOLLOW_type_app_in_type362);
                    	    ta=type_app();

                    	    state._fsp--;
                    	    if (state.failed) return retval;
                    	    if ( state.backtracking==0 ) stream_type_app.add(ta.getTree());
                    	    if ( state.backtracking==0 ) {
                    	      arrows.add((arrow19!=null?((Token)arrow19.start):null)); rest.add((ta!=null?((Object)ta.tree):null));
                    	    }

                    	    }
                    	    break;

                    	default :
                    	    break loop3;
                        }
                    } while (true);



                    // AST REWRITE
                    // elements: 
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    if ( state.backtracking==0 ) {
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 90:7: ->
                    {
                        adaptor.addChild(root_0, createArrowTree((Tree)(first!=null?((Object)first.tree):null), rest, arrows));

                    }

                    retval.tree = root_0;}
                    }
                    break;

            }
            retval.stop = input.LT(-1);

            if ( state.backtracking==0 ) {

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "type"

    public static class type_app_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "type_app"
    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:93:1: type_app : ( tid_star ( type_atom )+ -> ^( TCONS_APP tid_star ( type_atom )* ) | type_atom );
    public final TBTParser.type_app_return type_app() throws RecognitionException {
        TBTParser.type_app_return retval = new TBTParser.type_app_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        TBTParser.tid_star_return tid_star20 = null;

        TBTParser.type_atom_return type_atom21 = null;

        TBTParser.type_atom_return type_atom22 = null;


        RewriteRuleSubtreeStream stream_tid_star=new RewriteRuleSubtreeStream(adaptor,"rule tid_star");
        RewriteRuleSubtreeStream stream_type_atom=new RewriteRuleSubtreeStream(adaptor,"rule type_atom");
        try {
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:94:5: ( tid_star ( type_atom )+ -> ^( TCONS_APP tid_star ( type_atom )* ) | type_atom )
            int alt6=2;
            int LA6_0 = input.LA(1);

            if ( (LA6_0==TID) ) {
                switch ( input.LA(2) ) {
                case STAR:
                    {
                    int LA6_3 = input.LA(3);

                    if ( (LA6_3==ARROW||LA6_3==OR||LA6_3==RPAREN||(LA6_3>=RANG && LA6_3<=COLUMN)) ) {
                        alt6=2;
                    }
                    else if ( (LA6_3==LPAREN||LA6_3==TID) ) {
                        alt6=1;
                    }
                    else {
                        if (state.backtracking>0) {state.failed=true; return retval;}
                        NoViableAltException nvae =
                            new NoViableAltException("", 6, 3, input);

                        throw nvae;
                    }
                    }
                    break;
                case ARROW:
                case OR:
                case RPAREN:
                case RANG:
                case COLUMN:
                    {
                    alt6=2;
                    }
                    break;
                case LPAREN:
                case TID:
                    {
                    alt6=1;
                    }
                    break;
                default:
                    if (state.backtracking>0) {state.failed=true; return retval;}
                    NoViableAltException nvae =
                        new NoViableAltException("", 6, 1, input);

                    throw nvae;
                }

            }
            else if ( (LA6_0==LPAREN) ) {
                alt6=2;
            }
            else {
                if (state.backtracking>0) {state.failed=true; return retval;}
                NoViableAltException nvae =
                    new NoViableAltException("", 6, 0, input);

                throw nvae;
            }
            switch (alt6) {
                case 1 :
                    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:94:7: tid_star ( type_atom )+
                    {
                    pushFollow(FOLLOW_tid_star_in_type_app399);
                    tid_star20=tid_star();

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) stream_tid_star.add(tid_star20.getTree());
                    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:94:16: ( type_atom )+
                    int cnt5=0;
                    loop5:
                    do {
                        int alt5=2;
                        int LA5_0 = input.LA(1);

                        if ( (LA5_0==LPAREN||LA5_0==TID) ) {
                            alt5=1;
                        }


                        switch (alt5) {
                    	case 1 :
                    	    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:94:17: type_atom
                    	    {
                    	    pushFollow(FOLLOW_type_atom_in_type_app402);
                    	    type_atom21=type_atom();

                    	    state._fsp--;
                    	    if (state.failed) return retval;
                    	    if ( state.backtracking==0 ) stream_type_atom.add(type_atom21.getTree());

                    	    }
                    	    break;

                    	default :
                    	    if ( cnt5 >= 1 ) break loop5;
                    	    if (state.backtracking>0) {state.failed=true; return retval;}
                                EarlyExitException eee =
                                    new EarlyExitException(5, input);
                                throw eee;
                        }
                        cnt5++;
                    } while (true);



                    // AST REWRITE
                    // elements: type_atom, tid_star
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    if ( state.backtracking==0 ) {
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 95:9: -> ^( TCONS_APP tid_star ( type_atom )* )
                    {
                        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:95:12: ^( TCONS_APP tid_star ( type_atom )* )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(TCONS_APP, "TCONS_APP"), root_1);

                        adaptor.addChild(root_1, stream_tid_star.nextTree());
                        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:95:33: ( type_atom )*
                        while ( stream_type_atom.hasNext() ) {
                            adaptor.addChild(root_1, stream_type_atom.nextTree());

                        }
                        stream_type_atom.reset();

                        adaptor.addChild(root_0, root_1);
                        }

                    }

                    retval.tree = root_0;}
                    }
                    break;
                case 2 :
                    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:96:7: type_atom
                    {
                    root_0 = (Object)adaptor.nil();

                    pushFollow(FOLLOW_type_atom_in_type_app433);
                    type_atom22=type_atom();

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) adaptor.addChild(root_0, type_atom22.getTree());

                    }
                    break;

            }
            retval.stop = input.LT(-1);

            if ( state.backtracking==0 ) {

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "type_app"

    public static class type_atom_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "type_atom"
    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:99:1: type_atom : (c= tid_star -> {ctors.contains($c.name)}? ^( TCONS_APP $c) -> tid_star | LPAREN type RPAREN -> type );
    public final TBTParser.type_atom_return type_atom() throws RecognitionException {
        TBTParser.type_atom_return retval = new TBTParser.type_atom_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token LPAREN23=null;
        Token RPAREN25=null;
        TBTParser.tid_star_return c = null;

        TBTParser.type_return type24 = null;


        Object LPAREN23_tree=null;
        Object RPAREN25_tree=null;
        RewriteRuleTokenStream stream_RPAREN=new RewriteRuleTokenStream(adaptor,"token RPAREN");
        RewriteRuleTokenStream stream_LPAREN=new RewriteRuleTokenStream(adaptor,"token LPAREN");
        RewriteRuleSubtreeStream stream_type=new RewriteRuleSubtreeStream(adaptor,"rule type");
        RewriteRuleSubtreeStream stream_tid_star=new RewriteRuleSubtreeStream(adaptor,"rule tid_star");
        try {
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:100:5: (c= tid_star -> {ctors.contains($c.name)}? ^( TCONS_APP $c) -> tid_star | LPAREN type RPAREN -> type )
            int alt7=2;
            int LA7_0 = input.LA(1);

            if ( (LA7_0==TID) ) {
                alt7=1;
            }
            else if ( (LA7_0==LPAREN) ) {
                alt7=2;
            }
            else {
                if (state.backtracking>0) {state.failed=true; return retval;}
                NoViableAltException nvae =
                    new NoViableAltException("", 7, 0, input);

                throw nvae;
            }
            switch (alt7) {
                case 1 :
                    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:100:7: c= tid_star
                    {
                    pushFollow(FOLLOW_tid_star_in_type_atom454);
                    c=tid_star();

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) stream_tid_star.add(c.getTree());


                    // AST REWRITE
                    // elements: c, tid_star
                    // token labels: 
                    // rule labels: retval, c
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    if ( state.backtracking==0 ) {
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);
                    RewriteRuleSubtreeStream stream_c=new RewriteRuleSubtreeStream(adaptor,"rule c",c!=null?c.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 101:9: -> {ctors.contains($c.name)}? ^( TCONS_APP $c)
                    if (ctors.contains((c!=null?c.name:null))) {
                        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:101:39: ^( TCONS_APP $c)
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(TCONS_APP, "TCONS_APP"), root_1);

                        adaptor.addChild(root_1, stream_c.nextTree());

                        adaptor.addChild(root_0, root_1);
                        }

                    }
                    else // 102:9: -> tid_star
                    {
                        adaptor.addChild(root_0, stream_tid_star.nextTree());

                    }

                    retval.tree = root_0;}
                    }
                    break;
                case 2 :
                    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:103:7: LPAREN type RPAREN
                    {
                    LPAREN23=(Token)match(input,LPAREN,FOLLOW_LPAREN_in_type_atom493); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_LPAREN.add(LPAREN23);

                    pushFollow(FOLLOW_type_in_type_atom495);
                    type24=type();

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) stream_type.add(type24.getTree());
                    RPAREN25=(Token)match(input,RPAREN,FOLLOW_RPAREN_in_type_atom497); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_RPAREN.add(RPAREN25);



                    // AST REWRITE
                    // elements: type
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    if ( state.backtracking==0 ) {
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 103:27: -> type
                    {
                        adaptor.addChild(root_0, stream_type.nextTree());

                    }

                    retval.tree = root_0;}
                    }
                    break;

            }
            retval.stop = input.LT(-1);

            if ( state.backtracking==0 ) {

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "type_atom"

    public static class tid_star_return extends ParserRuleReturnScope {
        public String name;
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "tid_star"
    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:106:1: tid_star returns [String name] : ( TID STAR -> ^( TVAR ^( STARED_TYPE TID ) ) | TID -> ^( TVAR TID ) );
    public final TBTParser.tid_star_return tid_star() throws RecognitionException {
        TBTParser.tid_star_return retval = new TBTParser.tid_star_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token TID26=null;
        Token STAR27=null;
        Token TID28=null;

        Object TID26_tree=null;
        Object STAR27_tree=null;
        Object TID28_tree=null;
        RewriteRuleTokenStream stream_TID=new RewriteRuleTokenStream(adaptor,"token TID");
        RewriteRuleTokenStream stream_STAR=new RewriteRuleTokenStream(adaptor,"token STAR");

        try {
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:108:5: ( TID STAR -> ^( TVAR ^( STARED_TYPE TID ) ) | TID -> ^( TVAR TID ) )
            int alt8=2;
            int LA8_0 = input.LA(1);

            if ( (LA8_0==TID) ) {
                int LA8_1 = input.LA(2);

                if ( (LA8_1==STAR) ) {
                    alt8=1;
                }
                else if ( (LA8_1==ARROW||LA8_1==OR||(LA8_1>=LPAREN && LA8_1<=RPAREN)||(LA8_1>=RANG && LA8_1<=COLUMN)||LA8_1==TID) ) {
                    alt8=2;
                }
                else {
                    if (state.backtracking>0) {state.failed=true; return retval;}
                    NoViableAltException nvae =
                        new NoViableAltException("", 8, 1, input);

                    throw nvae;
                }
            }
            else {
                if (state.backtracking>0) {state.failed=true; return retval;}
                NoViableAltException nvae =
                    new NoViableAltException("", 8, 0, input);

                throw nvae;
            }
            switch (alt8) {
                case 1 :
                    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:108:7: TID STAR
                    {
                    TID26=(Token)match(input,TID,FOLLOW_TID_in_tid_star529); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_TID.add(TID26);

                    STAR27=(Token)match(input,STAR,FOLLOW_STAR_in_tid_star531); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_STAR.add(STAR27);

                    if ( state.backtracking==0 ) {
                      retval.name = (TID26!=null?TID26.getText():null); 
                    }


                    // AST REWRITE
                    // elements: TID
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    if ( state.backtracking==0 ) {
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 108:39: -> ^( TVAR ^( STARED_TYPE TID ) )
                    {
                        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:108:42: ^( TVAR ^( STARED_TYPE TID ) )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(TVAR, "TVAR"), root_1);

                        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:108:49: ^( STARED_TYPE TID )
                        {
                        Object root_2 = (Object)adaptor.nil();
                        root_2 = (Object)adaptor.becomeRoot((Object)adaptor.create(STARED_TYPE, "STARED_TYPE"), root_2);

                        adaptor.addChild(root_2, stream_TID.nextNode());

                        adaptor.addChild(root_1, root_2);
                        }

                        adaptor.addChild(root_0, root_1);
                        }

                    }

                    retval.tree = root_0;}
                    }
                    break;
                case 2 :
                    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:109:7: TID
                    {
                    TID28=(Token)match(input,TID,FOLLOW_TID_in_tid_star555); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_TID.add(TID28);

                    if ( state.backtracking==0 ) {
                      retval.name = (TID28!=null?TID28.getText():null); 
                    }


                    // AST REWRITE
                    // elements: TID
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    if ( state.backtracking==0 ) {
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 109:39: -> ^( TVAR TID )
                    {
                        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:109:42: ^( TVAR TID )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(TVAR, "TVAR"), root_1);

                        adaptor.addChild(root_1, stream_TID.nextNode());

                        adaptor.addChild(root_0, root_1);
                        }

                    }

                    retval.tree = root_0;}
                    }
                    break;

            }
            retval.stop = input.LT(-1);

            if ( state.backtracking==0 ) {

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "tid_star"

    public static class term_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "term"
    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:113:1: term : ( term_atom -> term_atom ) ( ( LANG )=> LANG type RANG -> ^( TYPE_APP $term type ) | ( term_atom )=> term_atom -> ^( LAM_APP $term term_atom ) )* ;
    public final TBTParser.term_return term() throws RecognitionException {
        TBTParser.term_return retval = new TBTParser.term_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token LANG30=null;
        Token RANG32=null;
        TBTParser.term_atom_return term_atom29 = null;

        TBTParser.type_return type31 = null;

        TBTParser.term_atom_return term_atom33 = null;


        Object LANG30_tree=null;
        Object RANG32_tree=null;
        RewriteRuleTokenStream stream_RANG=new RewriteRuleTokenStream(adaptor,"token RANG");
        RewriteRuleTokenStream stream_LANG=new RewriteRuleTokenStream(adaptor,"token LANG");
        RewriteRuleSubtreeStream stream_term_atom=new RewriteRuleSubtreeStream(adaptor,"rule term_atom");
        RewriteRuleSubtreeStream stream_type=new RewriteRuleSubtreeStream(adaptor,"rule type");
        try {
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:114:5: ( ( term_atom -> term_atom ) ( ( LANG )=> LANG type RANG -> ^( TYPE_APP $term type ) | ( term_atom )=> term_atom -> ^( LAM_APP $term term_atom ) )* )
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:114:7: ( term_atom -> term_atom ) ( ( LANG )=> LANG type RANG -> ^( TYPE_APP $term type ) | ( term_atom )=> term_atom -> ^( LAM_APP $term term_atom ) )*
            {
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:114:7: ( term_atom -> term_atom )
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:114:8: term_atom
            {
            pushFollow(FOLLOW_term_atom_in_term596);
            term_atom29=term_atom();

            state._fsp--;
            if (state.failed) return retval;
            if ( state.backtracking==0 ) stream_term_atom.add(term_atom29.getTree());


            // AST REWRITE
            // elements: term_atom
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            if ( state.backtracking==0 ) {
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 114:18: -> term_atom
            {
                adaptor.addChild(root_0, stream_term_atom.nextTree());

            }

            retval.tree = root_0;}
            }

            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:115:17: ( ( LANG )=> LANG type RANG -> ^( TYPE_APP $term type ) | ( term_atom )=> term_atom -> ^( LAM_APP $term term_atom ) )*
            loop9:
            do {
                int alt9=3;
                alt9 = dfa9.predict(input);
                switch (alt9) {
            	case 1 :
            	    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:115:19: ( LANG )=> LANG type RANG
            	    {
            	    LANG30=(Token)match(input,LANG,FOLLOW_LANG_in_term627); if (state.failed) return retval; 
            	    if ( state.backtracking==0 ) stream_LANG.add(LANG30);

            	    pushFollow(FOLLOW_type_in_term629);
            	    type31=type();

            	    state._fsp--;
            	    if (state.failed) return retval;
            	    if ( state.backtracking==0 ) stream_type.add(type31.getTree());
            	    RANG32=(Token)match(input,RANG,FOLLOW_RANG_in_term631); if (state.failed) return retval; 
            	    if ( state.backtracking==0 ) stream_RANG.add(RANG32);



            	    // AST REWRITE
            	    // elements: term, type
            	    // token labels: 
            	    // rule labels: retval
            	    // token list labels: 
            	    // rule list labels: 
            	    // wildcard labels: 
            	    if ( state.backtracking==0 ) {
            	    retval.tree = root_0;
            	    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            	    root_0 = (Object)adaptor.nil();
            	    // 115:43: -> ^( TYPE_APP $term type )
            	    {
            	        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:115:46: ^( TYPE_APP $term type )
            	        {
            	        Object root_1 = (Object)adaptor.nil();
            	        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(TYPE_APP, "TYPE_APP"), root_1);

            	        adaptor.addChild(root_1, stream_retval.nextTree());
            	        adaptor.addChild(root_1, stream_type.nextTree());

            	        adaptor.addChild(root_0, root_1);
            	        }

            	    }

            	    retval.tree = root_0;}
            	    }
            	    break;
            	case 2 :
            	    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:116:19: ( term_atom )=> term_atom
            	    {
            	    pushFollow(FOLLOW_term_atom_in_term668);
            	    term_atom33=term_atom();

            	    state._fsp--;
            	    if (state.failed) return retval;
            	    if ( state.backtracking==0 ) stream_term_atom.add(term_atom33.getTree());


            	    // AST REWRITE
            	    // elements: term_atom, term
            	    // token labels: 
            	    // rule labels: retval
            	    // token list labels: 
            	    // rule list labels: 
            	    // wildcard labels: 
            	    if ( state.backtracking==0 ) {
            	    retval.tree = root_0;
            	    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            	    root_0 = (Object)adaptor.nil();
            	    // 116:44: -> ^( LAM_APP $term term_atom )
            	    {
            	        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:116:47: ^( LAM_APP $term term_atom )
            	        {
            	        Object root_1 = (Object)adaptor.nil();
            	        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(LAM_APP, "LAM_APP"), root_1);

            	        adaptor.addChild(root_1, stream_retval.nextTree());
            	        adaptor.addChild(root_1, stream_term_atom.nextTree());

            	        adaptor.addChild(root_0, root_1);
            	        }

            	    }

            	    retval.tree = root_0;}
            	    }
            	    break;

            	default :
            	    break loop9;
                }
            } while (true);


            }

            retval.stop = input.LT(-1);

            if ( state.backtracking==0 ) {

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "term"

    public static class term_atom_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "term_atom"
    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:120:1: term_atom : ( LPAREN term RPAREN -> term | TLAMBDA TID DOT term -> ^( TYPE_ABS TID term ) | LAMBDA LANG type RANG ID DARROW term -> ^( LAM_ABS ID type term ) | LETREC LANG star_type RANG ID BIND term -> ^( LETREC star_type ID term ) | CASE LANG type RANG term OF LCURLY variant ( OR variant )* RCURLY -> ^( CASE type term ^( BRANCHES ( variant )* ) ) | ID -> ^( VAR ID ) );
    public final TBTParser.term_atom_return term_atom() throws RecognitionException {
        TBTParser.term_atom_return retval = new TBTParser.term_atom_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token LPAREN34=null;
        Token RPAREN36=null;
        Token TLAMBDA37=null;
        Token TID38=null;
        Token DOT39=null;
        Token LAMBDA41=null;
        Token LANG42=null;
        Token RANG44=null;
        Token ID45=null;
        Token DARROW46=null;
        Token LETREC48=null;
        Token LANG49=null;
        Token RANG51=null;
        Token ID52=null;
        Token BIND53=null;
        Token CASE55=null;
        Token LANG56=null;
        Token RANG58=null;
        Token OF60=null;
        Token LCURLY61=null;
        Token OR63=null;
        Token RCURLY65=null;
        Token ID66=null;
        TBTParser.term_return term35 = null;

        TBTParser.term_return term40 = null;

        TBTParser.type_return type43 = null;

        TBTParser.term_return term47 = null;

        TBTParser.star_type_return star_type50 = null;

        TBTParser.term_return term54 = null;

        TBTParser.type_return type57 = null;

        TBTParser.term_return term59 = null;

        TBTParser.variant_return variant62 = null;

        TBTParser.variant_return variant64 = null;


        Object LPAREN34_tree=null;
        Object RPAREN36_tree=null;
        Object TLAMBDA37_tree=null;
        Object TID38_tree=null;
        Object DOT39_tree=null;
        Object LAMBDA41_tree=null;
        Object LANG42_tree=null;
        Object RANG44_tree=null;
        Object ID45_tree=null;
        Object DARROW46_tree=null;
        Object LETREC48_tree=null;
        Object LANG49_tree=null;
        Object RANG51_tree=null;
        Object ID52_tree=null;
        Object BIND53_tree=null;
        Object CASE55_tree=null;
        Object LANG56_tree=null;
        Object RANG58_tree=null;
        Object OF60_tree=null;
        Object LCURLY61_tree=null;
        Object OR63_tree=null;
        Object RCURLY65_tree=null;
        Object ID66_tree=null;
        RewriteRuleTokenStream stream_RPAREN=new RewriteRuleTokenStream(adaptor,"token RPAREN");
        RewriteRuleTokenStream stream_LETREC=new RewriteRuleTokenStream(adaptor,"token LETREC");
        RewriteRuleTokenStream stream_RANG=new RewriteRuleTokenStream(adaptor,"token RANG");
        RewriteRuleTokenStream stream_BIND=new RewriteRuleTokenStream(adaptor,"token BIND");
        RewriteRuleTokenStream stream_OR=new RewriteRuleTokenStream(adaptor,"token OR");
        RewriteRuleTokenStream stream_RCURLY=new RewriteRuleTokenStream(adaptor,"token RCURLY");
        RewriteRuleTokenStream stream_CASE=new RewriteRuleTokenStream(adaptor,"token CASE");
        RewriteRuleTokenStream stream_DARROW=new RewriteRuleTokenStream(adaptor,"token DARROW");
        RewriteRuleTokenStream stream_LCURLY=new RewriteRuleTokenStream(adaptor,"token LCURLY");
        RewriteRuleTokenStream stream_TID=new RewriteRuleTokenStream(adaptor,"token TID");
        RewriteRuleTokenStream stream_LAMBDA=new RewriteRuleTokenStream(adaptor,"token LAMBDA");
        RewriteRuleTokenStream stream_DOT=new RewriteRuleTokenStream(adaptor,"token DOT");
        RewriteRuleTokenStream stream_ID=new RewriteRuleTokenStream(adaptor,"token ID");
        RewriteRuleTokenStream stream_OF=new RewriteRuleTokenStream(adaptor,"token OF");
        RewriteRuleTokenStream stream_LPAREN=new RewriteRuleTokenStream(adaptor,"token LPAREN");
        RewriteRuleTokenStream stream_TLAMBDA=new RewriteRuleTokenStream(adaptor,"token TLAMBDA");
        RewriteRuleTokenStream stream_LANG=new RewriteRuleTokenStream(adaptor,"token LANG");
        RewriteRuleSubtreeStream stream_term=new RewriteRuleSubtreeStream(adaptor,"rule term");
        RewriteRuleSubtreeStream stream_star_type=new RewriteRuleSubtreeStream(adaptor,"rule star_type");
        RewriteRuleSubtreeStream stream_type=new RewriteRuleSubtreeStream(adaptor,"rule type");
        RewriteRuleSubtreeStream stream_variant=new RewriteRuleSubtreeStream(adaptor,"rule variant");
        try {
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:121:5: ( LPAREN term RPAREN -> term | TLAMBDA TID DOT term -> ^( TYPE_ABS TID term ) | LAMBDA LANG type RANG ID DARROW term -> ^( LAM_ABS ID type term ) | LETREC LANG star_type RANG ID BIND term -> ^( LETREC star_type ID term ) | CASE LANG type RANG term OF LCURLY variant ( OR variant )* RCURLY -> ^( CASE type term ^( BRANCHES ( variant )* ) ) | ID -> ^( VAR ID ) )
            int alt11=6;
            switch ( input.LA(1) ) {
            case LPAREN:
                {
                alt11=1;
                }
                break;
            case TLAMBDA:
                {
                alt11=2;
                }
                break;
            case LAMBDA:
                {
                alt11=3;
                }
                break;
            case LETREC:
                {
                alt11=4;
                }
                break;
            case CASE:
                {
                alt11=5;
                }
                break;
            case ID:
                {
                alt11=6;
                }
                break;
            default:
                if (state.backtracking>0) {state.failed=true; return retval;}
                NoViableAltException nvae =
                    new NoViableAltException("", 11, 0, input);

                throw nvae;
            }

            switch (alt11) {
                case 1 :
                    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:121:7: LPAREN term RPAREN
                    {
                    LPAREN34=(Token)match(input,LPAREN,FOLLOW_LPAREN_in_term_atom720); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_LPAREN.add(LPAREN34);

                    pushFollow(FOLLOW_term_in_term_atom722);
                    term35=term();

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) stream_term.add(term35.getTree());
                    RPAREN36=(Token)match(input,RPAREN,FOLLOW_RPAREN_in_term_atom724); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_RPAREN.add(RPAREN36);



                    // AST REWRITE
                    // elements: term
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    if ( state.backtracking==0 ) {
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 122:7: -> term
                    {
                        adaptor.addChild(root_0, stream_term.nextTree());

                    }

                    retval.tree = root_0;}
                    }
                    break;
                case 2 :
                    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:123:7: TLAMBDA TID DOT term
                    {
                    TLAMBDA37=(Token)match(input,TLAMBDA,FOLLOW_TLAMBDA_in_term_atom742); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_TLAMBDA.add(TLAMBDA37);

                    TID38=(Token)match(input,TID,FOLLOW_TID_in_term_atom744); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_TID.add(TID38);

                    DOT39=(Token)match(input,DOT,FOLLOW_DOT_in_term_atom746); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_DOT.add(DOT39);

                    pushFollow(FOLLOW_term_in_term_atom748);
                    term40=term();

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) stream_term.add(term40.getTree());


                    // AST REWRITE
                    // elements: TID, term
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    if ( state.backtracking==0 ) {
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 124:7: -> ^( TYPE_ABS TID term )
                    {
                        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:124:10: ^( TYPE_ABS TID term )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(TYPE_ABS, "TYPE_ABS"), root_1);

                        adaptor.addChild(root_1, stream_TID.nextNode());
                        adaptor.addChild(root_1, stream_term.nextTree());

                        adaptor.addChild(root_0, root_1);
                        }

                    }

                    retval.tree = root_0;}
                    }
                    break;
                case 3 :
                    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:125:7: LAMBDA LANG type RANG ID DARROW term
                    {
                    LAMBDA41=(Token)match(input,LAMBDA,FOLLOW_LAMBDA_in_term_atom772); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_LAMBDA.add(LAMBDA41);

                    LANG42=(Token)match(input,LANG,FOLLOW_LANG_in_term_atom774); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_LANG.add(LANG42);

                    pushFollow(FOLLOW_type_in_term_atom776);
                    type43=type();

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) stream_type.add(type43.getTree());
                    RANG44=(Token)match(input,RANG,FOLLOW_RANG_in_term_atom778); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_RANG.add(RANG44);

                    ID45=(Token)match(input,ID,FOLLOW_ID_in_term_atom780); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_ID.add(ID45);

                    DARROW46=(Token)match(input,DARROW,FOLLOW_DARROW_in_term_atom783); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_DARROW.add(DARROW46);

                    pushFollow(FOLLOW_term_in_term_atom785);
                    term47=term();

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) stream_term.add(term47.getTree());


                    // AST REWRITE
                    // elements: type, ID, term
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    if ( state.backtracking==0 ) {
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 126:7: -> ^( LAM_ABS ID type term )
                    {
                        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:126:10: ^( LAM_ABS ID type term )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(LAM_ABS, "LAM_ABS"), root_1);

                        adaptor.addChild(root_1, stream_ID.nextNode());
                        adaptor.addChild(root_1, stream_type.nextTree());
                        adaptor.addChild(root_1, stream_term.nextTree());

                        adaptor.addChild(root_0, root_1);
                        }

                    }

                    retval.tree = root_0;}
                    }
                    break;
                case 4 :
                    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:127:7: LETREC LANG star_type RANG ID BIND term
                    {
                    LETREC48=(Token)match(input,LETREC,FOLLOW_LETREC_in_term_atom811); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_LETREC.add(LETREC48);

                    LANG49=(Token)match(input,LANG,FOLLOW_LANG_in_term_atom813); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_LANG.add(LANG49);

                    pushFollow(FOLLOW_star_type_in_term_atom815);
                    star_type50=star_type();

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) stream_star_type.add(star_type50.getTree());
                    RANG51=(Token)match(input,RANG,FOLLOW_RANG_in_term_atom817); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_RANG.add(RANG51);

                    ID52=(Token)match(input,ID,FOLLOW_ID_in_term_atom819); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_ID.add(ID52);

                    BIND53=(Token)match(input,BIND,FOLLOW_BIND_in_term_atom821); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_BIND.add(BIND53);

                    pushFollow(FOLLOW_term_in_term_atom823);
                    term54=term();

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) stream_term.add(term54.getTree());


                    // AST REWRITE
                    // elements: term, LETREC, ID, star_type
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    if ( state.backtracking==0 ) {
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 128:7: -> ^( LETREC star_type ID term )
                    {
                        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:128:10: ^( LETREC star_type ID term )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot(stream_LETREC.nextNode(), root_1);

                        adaptor.addChild(root_1, stream_star_type.nextTree());
                        adaptor.addChild(root_1, stream_ID.nextNode());
                        adaptor.addChild(root_1, stream_term.nextTree());

                        adaptor.addChild(root_0, root_1);
                        }

                    }

                    retval.tree = root_0;}
                    }
                    break;
                case 5 :
                    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:129:7: CASE LANG type RANG term OF LCURLY variant ( OR variant )* RCURLY
                    {
                    CASE55=(Token)match(input,CASE,FOLLOW_CASE_in_term_atom850); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_CASE.add(CASE55);

                    LANG56=(Token)match(input,LANG,FOLLOW_LANG_in_term_atom852); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_LANG.add(LANG56);

                    pushFollow(FOLLOW_type_in_term_atom854);
                    type57=type();

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) stream_type.add(type57.getTree());
                    RANG58=(Token)match(input,RANG,FOLLOW_RANG_in_term_atom856); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_RANG.add(RANG58);

                    pushFollow(FOLLOW_term_in_term_atom858);
                    term59=term();

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) stream_term.add(term59.getTree());
                    OF60=(Token)match(input,OF,FOLLOW_OF_in_term_atom860); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_OF.add(OF60);

                    LCURLY61=(Token)match(input,LCURLY,FOLLOW_LCURLY_in_term_atom862); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_LCURLY.add(LCURLY61);

                    pushFollow(FOLLOW_variant_in_term_atom864);
                    variant62=variant();

                    state._fsp--;
                    if (state.failed) return retval;
                    if ( state.backtracking==0 ) stream_variant.add(variant62.getTree());
                    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:129:50: ( OR variant )*
                    loop10:
                    do {
                        int alt10=2;
                        int LA10_0 = input.LA(1);

                        if ( (LA10_0==OR) ) {
                            alt10=1;
                        }


                        switch (alt10) {
                    	case 1 :
                    	    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:129:51: OR variant
                    	    {
                    	    OR63=(Token)match(input,OR,FOLLOW_OR_in_term_atom867); if (state.failed) return retval; 
                    	    if ( state.backtracking==0 ) stream_OR.add(OR63);

                    	    pushFollow(FOLLOW_variant_in_term_atom869);
                    	    variant64=variant();

                    	    state._fsp--;
                    	    if (state.failed) return retval;
                    	    if ( state.backtracking==0 ) stream_variant.add(variant64.getTree());

                    	    }
                    	    break;

                    	default :
                    	    break loop10;
                        }
                    } while (true);

                    RCURLY65=(Token)match(input,RCURLY,FOLLOW_RCURLY_in_term_atom873); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_RCURLY.add(RCURLY65);



                    // AST REWRITE
                    // elements: variant, type, term, CASE
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    if ( state.backtracking==0 ) {
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 130:7: -> ^( CASE type term ^( BRANCHES ( variant )* ) )
                    {
                        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:130:10: ^( CASE type term ^( BRANCHES ( variant )* ) )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot(stream_CASE.nextNode(), root_1);

                        adaptor.addChild(root_1, stream_type.nextTree());
                        adaptor.addChild(root_1, stream_term.nextTree());
                        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:130:27: ^( BRANCHES ( variant )* )
                        {
                        Object root_2 = (Object)adaptor.nil();
                        root_2 = (Object)adaptor.becomeRoot((Object)adaptor.create(BRANCHES, "BRANCHES"), root_2);

                        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:130:38: ( variant )*
                        while ( stream_variant.hasNext() ) {
                            adaptor.addChild(root_2, stream_variant.nextTree());

                        }
                        stream_variant.reset();

                        adaptor.addChild(root_1, root_2);
                        }

                        adaptor.addChild(root_0, root_1);
                        }

                    }

                    retval.tree = root_0;}
                    }
                    break;
                case 6 :
                    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:131:7: ID
                    {
                    ID66=(Token)match(input,ID,FOLLOW_ID_in_term_atom904); if (state.failed) return retval; 
                    if ( state.backtracking==0 ) stream_ID.add(ID66);



                    // AST REWRITE
                    // elements: ID
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    if ( state.backtracking==0 ) {
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 132:7: -> ^( VAR ID )
                    {
                        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:132:10: ^( VAR ID )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(VAR, "VAR"), root_1);

                        adaptor.addChild(root_1, stream_ID.nextNode());

                        adaptor.addChild(root_0, root_1);
                        }

                    }

                    retval.tree = root_0;}
                    }
                    break;

            }
            retval.stop = input.LT(-1);

            if ( state.backtracking==0 ) {

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "term_atom"

    public static class variant_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "variant"
    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:135:1: variant : ID DARROW term -> ^( BRANCH ID term ) ;
    public final TBTParser.variant_return variant() throws RecognitionException {
        TBTParser.variant_return retval = new TBTParser.variant_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token ID67=null;
        Token DARROW68=null;
        TBTParser.term_return term69 = null;


        Object ID67_tree=null;
        Object DARROW68_tree=null;
        RewriteRuleTokenStream stream_DARROW=new RewriteRuleTokenStream(adaptor,"token DARROW");
        RewriteRuleTokenStream stream_ID=new RewriteRuleTokenStream(adaptor,"token ID");
        RewriteRuleSubtreeStream stream_term=new RewriteRuleSubtreeStream(adaptor,"rule term");
        try {
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:136:5: ( ID DARROW term -> ^( BRANCH ID term ) )
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:136:7: ID DARROW term
            {
            ID67=(Token)match(input,ID,FOLLOW_ID_in_variant936); if (state.failed) return retval; 
            if ( state.backtracking==0 ) stream_ID.add(ID67);

            DARROW68=(Token)match(input,DARROW,FOLLOW_DARROW_in_variant938); if (state.failed) return retval; 
            if ( state.backtracking==0 ) stream_DARROW.add(DARROW68);

            pushFollow(FOLLOW_term_in_variant940);
            term69=term();

            state._fsp--;
            if (state.failed) return retval;
            if ( state.backtracking==0 ) stream_term.add(term69.getTree());


            // AST REWRITE
            // elements: term, ID
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            if ( state.backtracking==0 ) {
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 137:7: -> ^( BRANCH ID term )
            {
                // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:137:10: ^( BRANCH ID term )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(BRANCH, "BRANCH"), root_1);

                adaptor.addChild(root_1, stream_ID.nextNode());
                adaptor.addChild(root_1, stream_term.nextTree());

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;}
            }

            retval.stop = input.LT(-1);

            if ( state.backtracking==0 ) {

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "variant"

    public static class datatype_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "datatype"
    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:141:1: datatype : IND name= TID ( tid )* EQ constr ( OR constr )* COLUMN -> ^( DATATYPE $name ^( TARGS ( tid )* ) ^( TCONSTRUCTORS ( constr )* ) ) ;
    public final TBTParser.datatype_return datatype() throws RecognitionException {
        TBTParser.datatype_return retval = new TBTParser.datatype_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token name=null;
        Token IND70=null;
        Token EQ72=null;
        Token OR74=null;
        Token COLUMN76=null;
        TBTParser.tid_return tid71 = null;

        TBTParser.constr_return constr73 = null;

        TBTParser.constr_return constr75 = null;


        Object name_tree=null;
        Object IND70_tree=null;
        Object EQ72_tree=null;
        Object OR74_tree=null;
        Object COLUMN76_tree=null;
        RewriteRuleTokenStream stream_IND=new RewriteRuleTokenStream(adaptor,"token IND");
        RewriteRuleTokenStream stream_TID=new RewriteRuleTokenStream(adaptor,"token TID");
        RewriteRuleTokenStream stream_EQ=new RewriteRuleTokenStream(adaptor,"token EQ");
        RewriteRuleTokenStream stream_OR=new RewriteRuleTokenStream(adaptor,"token OR");
        RewriteRuleTokenStream stream_COLUMN=new RewriteRuleTokenStream(adaptor,"token COLUMN");
        RewriteRuleSubtreeStream stream_constr=new RewriteRuleSubtreeStream(adaptor,"rule constr");
        RewriteRuleSubtreeStream stream_tid=new RewriteRuleSubtreeStream(adaptor,"rule tid");
        try {
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:142:5: ( IND name= TID ( tid )* EQ constr ( OR constr )* COLUMN -> ^( DATATYPE $name ^( TARGS ( tid )* ) ^( TCONSTRUCTORS ( constr )* ) ) )
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:142:7: IND name= TID ( tid )* EQ constr ( OR constr )* COLUMN
            {
            IND70=(Token)match(input,IND,FOLLOW_IND_in_datatype976); if (state.failed) return retval; 
            if ( state.backtracking==0 ) stream_IND.add(IND70);

            name=(Token)match(input,TID,FOLLOW_TID_in_datatype980); if (state.failed) return retval; 
            if ( state.backtracking==0 ) stream_TID.add(name);

            if ( state.backtracking==0 ) {
              ctors.add((name!=null?name.getText():null));
            }
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:142:45: ( tid )*
            loop12:
            do {
                int alt12=2;
                int LA12_0 = input.LA(1);

                if ( (LA12_0==TID) ) {
                    alt12=1;
                }


                switch (alt12) {
            	case 1 :
            	    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:142:45: tid
            	    {
            	    pushFollow(FOLLOW_tid_in_datatype984);
            	    tid71=tid();

            	    state._fsp--;
            	    if (state.failed) return retval;
            	    if ( state.backtracking==0 ) stream_tid.add(tid71.getTree());

            	    }
            	    break;

            	default :
            	    break loop12;
                }
            } while (true);

            EQ72=(Token)match(input,EQ,FOLLOW_EQ_in_datatype987); if (state.failed) return retval; 
            if ( state.backtracking==0 ) stream_EQ.add(EQ72);

            pushFollow(FOLLOW_constr_in_datatype989);
            constr73=constr();

            state._fsp--;
            if (state.failed) return retval;
            if ( state.backtracking==0 ) stream_constr.add(constr73.getTree());
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:142:60: ( OR constr )*
            loop13:
            do {
                int alt13=2;
                int LA13_0 = input.LA(1);

                if ( (LA13_0==OR) ) {
                    alt13=1;
                }


                switch (alt13) {
            	case 1 :
            	    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:142:61: OR constr
            	    {
            	    OR74=(Token)match(input,OR,FOLLOW_OR_in_datatype992); if (state.failed) return retval; 
            	    if ( state.backtracking==0 ) stream_OR.add(OR74);

            	    pushFollow(FOLLOW_constr_in_datatype994);
            	    constr75=constr();

            	    state._fsp--;
            	    if (state.failed) return retval;
            	    if ( state.backtracking==0 ) stream_constr.add(constr75.getTree());

            	    }
            	    break;

            	default :
            	    break loop13;
                }
            } while (true);

            COLUMN76=(Token)match(input,COLUMN,FOLLOW_COLUMN_in_datatype998); if (state.failed) return retval; 
            if ( state.backtracking==0 ) stream_COLUMN.add(COLUMN76);



            // AST REWRITE
            // elements: tid, constr, name
            // token labels: name
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            if ( state.backtracking==0 ) {
            retval.tree = root_0;
            RewriteRuleTokenStream stream_name=new RewriteRuleTokenStream(adaptor,"token name",name);
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 143:7: -> ^( DATATYPE $name ^( TARGS ( tid )* ) ^( TCONSTRUCTORS ( constr )* ) )
            {
                // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:143:10: ^( DATATYPE $name ^( TARGS ( tid )* ) ^( TCONSTRUCTORS ( constr )* ) )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(DATATYPE, "DATATYPE"), root_1);

                adaptor.addChild(root_1, stream_name.nextNode());
                // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:143:27: ^( TARGS ( tid )* )
                {
                Object root_2 = (Object)adaptor.nil();
                root_2 = (Object)adaptor.becomeRoot((Object)adaptor.create(TARGS, "TARGS"), root_2);

                // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:143:35: ( tid )*
                while ( stream_tid.hasNext() ) {
                    adaptor.addChild(root_2, stream_tid.nextTree());

                }
                stream_tid.reset();

                adaptor.addChild(root_1, root_2);
                }
                // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:143:41: ^( TCONSTRUCTORS ( constr )* )
                {
                Object root_2 = (Object)adaptor.nil();
                root_2 = (Object)adaptor.becomeRoot((Object)adaptor.create(TCONSTRUCTORS, "TCONSTRUCTORS"), root_2);

                // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:143:57: ( constr )*
                while ( stream_constr.hasNext() ) {
                    adaptor.addChild(root_2, stream_constr.nextTree());

                }
                stream_constr.reset();

                adaptor.addChild(root_1, root_2);
                }

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;}
            }

            retval.stop = input.LT(-1);

            if ( state.backtracking==0 ) {

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "datatype"

    public static class tid_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "tid"
    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:145:1: tid : TID ;
    public final TBTParser.tid_return tid() throws RecognitionException {
        TBTParser.tid_return retval = new TBTParser.tid_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token TID77=null;

        Object TID77_tree=null;

        try {
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:145:5: ( TID )
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:145:7: TID
            {
            root_0 = (Object)adaptor.nil();

            TID77=(Token)match(input,TID,FOLLOW_TID_in_tid1042); if (state.failed) return retval;
            if ( state.backtracking==0 ) {
            TID77_tree = (Object)adaptor.create(TID77);
            adaptor.addChild(root_0, TID77_tree);
            }

            }

            retval.stop = input.LT(-1);

            if ( state.backtracking==0 ) {

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "tid"

    public static class constr_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "constr"
    // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:147:1: constr : ID SEMI type -> ^( TCONS ID type ) ;
    public final TBTParser.constr_return constr() throws RecognitionException {
        TBTParser.constr_return retval = new TBTParser.constr_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token ID78=null;
        Token SEMI79=null;
        TBTParser.type_return type80 = null;


        Object ID78_tree=null;
        Object SEMI79_tree=null;
        RewriteRuleTokenStream stream_ID=new RewriteRuleTokenStream(adaptor,"token ID");
        RewriteRuleTokenStream stream_SEMI=new RewriteRuleTokenStream(adaptor,"token SEMI");
        RewriteRuleSubtreeStream stream_type=new RewriteRuleSubtreeStream(adaptor,"rule type");
        try {
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:148:5: ( ID SEMI type -> ^( TCONS ID type ) )
            // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:148:7: ID SEMI type
            {
            ID78=(Token)match(input,ID,FOLLOW_ID_in_constr1057); if (state.failed) return retval; 
            if ( state.backtracking==0 ) stream_ID.add(ID78);

            SEMI79=(Token)match(input,SEMI,FOLLOW_SEMI_in_constr1059); if (state.failed) return retval; 
            if ( state.backtracking==0 ) stream_SEMI.add(SEMI79);

            pushFollow(FOLLOW_type_in_constr1061);
            type80=type();

            state._fsp--;
            if (state.failed) return retval;
            if ( state.backtracking==0 ) stream_type.add(type80.getTree());


            // AST REWRITE
            // elements: type, ID
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            if ( state.backtracking==0 ) {
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 149:7: -> ^( TCONS ID type )
            {
                // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:149:10: ^( TCONS ID type )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(TCONS, "TCONS"), root_1);

                adaptor.addChild(root_1, stream_ID.nextNode());
                adaptor.addChild(root_1, stream_type.nextTree());

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;}
            }

            retval.stop = input.LT(-1);

            if ( state.backtracking==0 ) {

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "constr"

    // $ANTLR start synpred1_TBTParser
    public final void synpred1_TBTParser_fragment() throws RecognitionException {   
        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:89:23: ( ARROW )
        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:89:24: ARROW
        {
        match(input,ARROW,FOLLOW_ARROW_in_synpred1_TBTParser355); if (state.failed) return ;

        }
    }
    // $ANTLR end synpred1_TBTParser

    // $ANTLR start synpred2_TBTParser
    public final void synpred2_TBTParser_fragment() throws RecognitionException {   
        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:115:19: ( LANG )
        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:115:20: LANG
        {
        match(input,LANG,FOLLOW_LANG_in_synpred2_TBTParser623); if (state.failed) return ;

        }
    }
    // $ANTLR end synpred2_TBTParser

    // $ANTLR start synpred3_TBTParser
    public final void synpred3_TBTParser_fragment() throws RecognitionException {   
        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:116:19: ( term_atom )
        // D:\\workspace\\TBT-front-end\\grammar\\TBTParser.g:116:20: term_atom
        {
        pushFollow(FOLLOW_term_atom_in_synpred3_TBTParser663);
        term_atom();

        state._fsp--;
        if (state.failed) return ;

        }
    }
    // $ANTLR end synpred3_TBTParser

    // Delegated rules

    public final boolean synpred3_TBTParser() {
        state.backtracking++;
        int start = input.mark();
        try {
            synpred3_TBTParser_fragment(); // can never throw exception
        } catch (RecognitionException re) {
            System.err.println("impossible: "+re);
        }
        boolean success = !state.failed;
        input.rewind(start);
        state.backtracking--;
        state.failed=false;
        return success;
    }
    public final boolean synpred1_TBTParser() {
        state.backtracking++;
        int start = input.mark();
        try {
            synpred1_TBTParser_fragment(); // can never throw exception
        } catch (RecognitionException re) {
            System.err.println("impossible: "+re);
        }
        boolean success = !state.failed;
        input.rewind(start);
        state.backtracking--;
        state.failed=false;
        return success;
    }
    public final boolean synpred2_TBTParser() {
        state.backtracking++;
        int start = input.mark();
        try {
            synpred2_TBTParser_fragment(); // can never throw exception
        } catch (RecognitionException re) {
            System.err.println("impossible: "+re);
        }
        boolean success = !state.failed;
        input.rewind(start);
        state.backtracking--;
        state.failed=false;
        return success;
    }


    protected DFA9 dfa9 = new DFA9(this);
    static final String DFA9_eotS =
        "\13\uffff";
    static final String DFA9_eofS =
        "\1\1\12\uffff";
    static final String DFA9_minS =
        "\1\11\1\uffff\7\0\2\uffff";
    static final String DFA9_maxS =
        "\1\37\1\uffff\7\0\2\uffff";
    static final String DFA9_acceptS =
        "\1\uffff\1\3\7\uffff\1\1\1\2";
    static final String DFA9_specialS =
        "\2\uffff\1\0\1\5\1\2\1\4\1\1\1\6\1\3\2\uffff}>";
    static final String[] DFA9_transitionS = {
            "\1\4\1\5\4\uffff\1\1\2\uffff\1\6\1\uffff\1\7\1\1\2\uffff\1"+
            "\3\1\1\1\uffff\1\1\1\2\1\uffff\1\1\1\10",
            "",
            "\1\uffff",
            "\1\uffff",
            "\1\uffff",
            "\1\uffff",
            "\1\uffff",
            "\1\uffff",
            "\1\uffff",
            "",
            ""
    };

    static final short[] DFA9_eot = DFA.unpackEncodedString(DFA9_eotS);
    static final short[] DFA9_eof = DFA.unpackEncodedString(DFA9_eofS);
    static final char[] DFA9_min = DFA.unpackEncodedStringToUnsignedChars(DFA9_minS);
    static final char[] DFA9_max = DFA.unpackEncodedStringToUnsignedChars(DFA9_maxS);
    static final short[] DFA9_accept = DFA.unpackEncodedString(DFA9_acceptS);
    static final short[] DFA9_special = DFA.unpackEncodedString(DFA9_specialS);
    static final short[][] DFA9_transition;

    static {
        int numStates = DFA9_transitionS.length;
        DFA9_transition = new short[numStates][];
        for (int i=0; i<numStates; i++) {
            DFA9_transition[i] = DFA.unpackEncodedString(DFA9_transitionS[i]);
        }
    }

    class DFA9 extends DFA {

        public DFA9(BaseRecognizer recognizer) {
            this.recognizer = recognizer;
            this.decisionNumber = 9;
            this.eot = DFA9_eot;
            this.eof = DFA9_eof;
            this.min = DFA9_min;
            this.max = DFA9_max;
            this.accept = DFA9_accept;
            this.special = DFA9_special;
            this.transition = DFA9_transition;
        }
        public String getDescription() {
            return "()* loopback of 115:17: ( ( LANG )=> LANG type RANG -> ^( TYPE_APP $term type ) | ( term_atom )=> term_atom -> ^( LAM_APP $term term_atom ) )*";
        }
        public int specialStateTransition(int s, IntStream _input) throws NoViableAltException {
            TokenStream input = (TokenStream)_input;
        	int _s = s;
            switch ( s ) {
                    case 0 : 
                        int LA9_2 = input.LA(1);

                         
                        int index9_2 = input.index();
                        input.rewind();
                        s = -1;
                        if ( (synpred2_TBTParser()) ) {s = 9;}

                        else if ( (true) ) {s = 1;}

                         
                        input.seek(index9_2);
                        if ( s>=0 ) return s;
                        break;
                    case 1 : 
                        int LA9_6 = input.LA(1);

                         
                        int index9_6 = input.index();
                        input.rewind();
                        s = -1;
                        if ( (synpred3_TBTParser()) ) {s = 10;}

                        else if ( (true) ) {s = 1;}

                         
                        input.seek(index9_6);
                        if ( s>=0 ) return s;
                        break;
                    case 2 : 
                        int LA9_4 = input.LA(1);

                         
                        int index9_4 = input.index();
                        input.rewind();
                        s = -1;
                        if ( (synpred3_TBTParser()) ) {s = 10;}

                        else if ( (true) ) {s = 1;}

                         
                        input.seek(index9_4);
                        if ( s>=0 ) return s;
                        break;
                    case 3 : 
                        int LA9_8 = input.LA(1);

                         
                        int index9_8 = input.index();
                        input.rewind();
                        s = -1;
                        if ( (synpred3_TBTParser()) ) {s = 10;}

                        else if ( (true) ) {s = 1;}

                         
                        input.seek(index9_8);
                        if ( s>=0 ) return s;
                        break;
                    case 4 : 
                        int LA9_5 = input.LA(1);

                         
                        int index9_5 = input.index();
                        input.rewind();
                        s = -1;
                        if ( (synpred3_TBTParser()) ) {s = 10;}

                        else if ( (true) ) {s = 1;}

                         
                        input.seek(index9_5);
                        if ( s>=0 ) return s;
                        break;
                    case 5 : 
                        int LA9_3 = input.LA(1);

                         
                        int index9_3 = input.index();
                        input.rewind();
                        s = -1;
                        if ( (synpred3_TBTParser()) ) {s = 10;}

                        else if ( (true) ) {s = 1;}

                         
                        input.seek(index9_3);
                        if ( s>=0 ) return s;
                        break;
                    case 6 : 
                        int LA9_7 = input.LA(1);

                         
                        int index9_7 = input.index();
                        input.rewind();
                        s = -1;
                        if ( (synpred3_TBTParser()) ) {s = 10;}

                        else if ( (true) ) {s = 1;}

                         
                        input.seek(index9_7);
                        if ( s>=0 ) return s;
                        break;
            }
            if (state.backtracking>0) {state.failed=true; return -1;}
            NoViableAltException nvae =
                new NoViableAltException(getDescription(), 9, _s, input);
            error(nvae);
            throw nvae;
        }
    }
 

    public static final BitSet FOLLOW_prolog_in_program184 = new BitSet(new long[]{0x00000000811C0600L});
    public static final BitSet FOLLOW_tl_binding_in_program186 = new BitSet(new long[]{0x00000000811C0600L});
    public static final BitSet FOLLOW_term_in_program189 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_datatype_in_prolog224 = new BitSet(new long[]{0x0000000000400002L});
    public static final BitSet FOLLOW_LET_in_tl_binding248 = new BitSet(new long[]{0x0000000010000000L});
    public static final BitSet FOLLOW_LANG_in_tl_binding250 = new BitSet(new long[]{0x0000000101000080L});
    public static final BitSet FOLLOW_type_in_tl_binding252 = new BitSet(new long[]{0x0000000020000000L});
    public static final BitSet FOLLOW_RANG_in_tl_binding254 = new BitSet(new long[]{0x0000000080000000L});
    public static final BitSet FOLLOW_ID_in_tl_binding256 = new BitSet(new long[]{0x0000000000004000L});
    public static final BitSet FOLLOW_BIND_in_tl_binding258 = new BitSet(new long[]{0x00000000811C0600L});
    public static final BitSet FOLLOW_term_in_tl_binding260 = new BitSet(new long[]{0x0000000040000000L});
    public static final BitSet FOLLOW_COLUMN_in_tl_binding262 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ARROW_in_arrow293 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_type_in_star_type300 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_FORALL_in_type317 = new BitSet(new long[]{0x0000000100000000L});
    public static final BitSet FOLLOW_TID_in_type319 = new BitSet(new long[]{0x0000000000000800L});
    public static final BitSet FOLLOW_DOT_in_type321 = new BitSet(new long[]{0x0000000101000080L});
    public static final BitSet FOLLOW_type_in_type323 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_type_app_in_type351 = new BitSet(new long[]{0x0000000000000102L});
    public static final BitSet FOLLOW_arrow_in_type358 = new BitSet(new long[]{0x0000000101000080L});
    public static final BitSet FOLLOW_type_app_in_type362 = new BitSet(new long[]{0x0000000000000102L});
    public static final BitSet FOLLOW_tid_star_in_type_app399 = new BitSet(new long[]{0x0000000101000080L});
    public static final BitSet FOLLOW_type_atom_in_type_app402 = new BitSet(new long[]{0x0000000101000082L});
    public static final BitSet FOLLOW_type_atom_in_type_app433 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_tid_star_in_type_atom454 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_LPAREN_in_type_atom493 = new BitSet(new long[]{0x0000000101000080L});
    public static final BitSet FOLLOW_type_in_type_atom495 = new BitSet(new long[]{0x0000000002000000L});
    public static final BitSet FOLLOW_RPAREN_in_type_atom497 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_TID_in_tid_star529 = new BitSet(new long[]{0x0000000000020000L});
    public static final BitSet FOLLOW_STAR_in_tid_star531 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_TID_in_tid_star555 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_term_atom_in_term596 = new BitSet(new long[]{0x00000000911C0602L});
    public static final BitSet FOLLOW_LANG_in_term627 = new BitSet(new long[]{0x0000000101000080L});
    public static final BitSet FOLLOW_type_in_term629 = new BitSet(new long[]{0x0000000020000000L});
    public static final BitSet FOLLOW_RANG_in_term631 = new BitSet(new long[]{0x00000000911C0602L});
    public static final BitSet FOLLOW_term_atom_in_term668 = new BitSet(new long[]{0x00000000911C0602L});
    public static final BitSet FOLLOW_LPAREN_in_term_atom720 = new BitSet(new long[]{0x00000000811C0600L});
    public static final BitSet FOLLOW_term_in_term_atom722 = new BitSet(new long[]{0x0000000002000000L});
    public static final BitSet FOLLOW_RPAREN_in_term_atom724 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_TLAMBDA_in_term_atom742 = new BitSet(new long[]{0x0000000100000000L});
    public static final BitSet FOLLOW_TID_in_term_atom744 = new BitSet(new long[]{0x0000000000000800L});
    public static final BitSet FOLLOW_DOT_in_term_atom746 = new BitSet(new long[]{0x00000000811C0600L});
    public static final BitSet FOLLOW_term_in_term_atom748 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_LAMBDA_in_term_atom772 = new BitSet(new long[]{0x0000000010000000L});
    public static final BitSet FOLLOW_LANG_in_term_atom774 = new BitSet(new long[]{0x0000000101000080L});
    public static final BitSet FOLLOW_type_in_term_atom776 = new BitSet(new long[]{0x0000000020000000L});
    public static final BitSet FOLLOW_RANG_in_term_atom778 = new BitSet(new long[]{0x0000000080000000L});
    public static final BitSet FOLLOW_ID_in_term_atom780 = new BitSet(new long[]{0x0000000000010000L});
    public static final BitSet FOLLOW_DARROW_in_term_atom783 = new BitSet(new long[]{0x00000000811C0600L});
    public static final BitSet FOLLOW_term_in_term_atom785 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_LETREC_in_term_atom811 = new BitSet(new long[]{0x0000000010000000L});
    public static final BitSet FOLLOW_LANG_in_term_atom813 = new BitSet(new long[]{0x0000000101000080L});
    public static final BitSet FOLLOW_star_type_in_term_atom815 = new BitSet(new long[]{0x0000000020000000L});
    public static final BitSet FOLLOW_RANG_in_term_atom817 = new BitSet(new long[]{0x0000000080000000L});
    public static final BitSet FOLLOW_ID_in_term_atom819 = new BitSet(new long[]{0x0000000000004000L});
    public static final BitSet FOLLOW_BIND_in_term_atom821 = new BitSet(new long[]{0x00000000811C0600L});
    public static final BitSet FOLLOW_term_in_term_atom823 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_CASE_in_term_atom850 = new BitSet(new long[]{0x0000000010000000L});
    public static final BitSet FOLLOW_LANG_in_term_atom852 = new BitSet(new long[]{0x0000000101000080L});
    public static final BitSet FOLLOW_type_in_term_atom854 = new BitSet(new long[]{0x0000000020000000L});
    public static final BitSet FOLLOW_RANG_in_term_atom856 = new BitSet(new long[]{0x00000000811C0600L});
    public static final BitSet FOLLOW_term_in_term_atom858 = new BitSet(new long[]{0x0000000000200000L});
    public static final BitSet FOLLOW_OF_in_term_atom860 = new BitSet(new long[]{0x0000000004000000L});
    public static final BitSet FOLLOW_LCURLY_in_term_atom862 = new BitSet(new long[]{0x0000000080000000L});
    public static final BitSet FOLLOW_variant_in_term_atom864 = new BitSet(new long[]{0x0000000008008000L});
    public static final BitSet FOLLOW_OR_in_term_atom867 = new BitSet(new long[]{0x0000000080000000L});
    public static final BitSet FOLLOW_variant_in_term_atom869 = new BitSet(new long[]{0x0000000008008000L});
    public static final BitSet FOLLOW_RCURLY_in_term_atom873 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_term_atom904 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_variant936 = new BitSet(new long[]{0x0000000000010000L});
    public static final BitSet FOLLOW_DARROW_in_variant938 = new BitSet(new long[]{0x00000000811C0600L});
    public static final BitSet FOLLOW_term_in_variant940 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_IND_in_datatype976 = new BitSet(new long[]{0x0000000100000000L});
    public static final BitSet FOLLOW_TID_in_datatype980 = new BitSet(new long[]{0x0000000100002000L});
    public static final BitSet FOLLOW_tid_in_datatype984 = new BitSet(new long[]{0x0000000100002000L});
    public static final BitSet FOLLOW_EQ_in_datatype987 = new BitSet(new long[]{0x0000000080000000L});
    public static final BitSet FOLLOW_constr_in_datatype989 = new BitSet(new long[]{0x0000000040008000L});
    public static final BitSet FOLLOW_OR_in_datatype992 = new BitSet(new long[]{0x0000000080000000L});
    public static final BitSet FOLLOW_constr_in_datatype994 = new BitSet(new long[]{0x0000000040008000L});
    public static final BitSet FOLLOW_COLUMN_in_datatype998 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_TID_in_tid1042 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_constr1057 = new BitSet(new long[]{0x0000000000001000L});
    public static final BitSet FOLLOW_SEMI_in_constr1059 = new BitSet(new long[]{0x0000000101000080L});
    public static final BitSet FOLLOW_type_in_constr1061 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ARROW_in_synpred1_TBTParser355 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_LANG_in_synpred2_TBTParser623 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_term_atom_in_synpred3_TBTParser663 = new BitSet(new long[]{0x0000000000000002L});

}